Skip to content

fix(compiler-dom): handle v-model + v-bind shorthand type edge case #13170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

edison1105
Copy link
Member

@edison1105 edison1105 commented Apr 8, 2025

close #13169

Summary by CodeRabbit

  • Tests

    • Added a new test to ensure that input elements using shorthand dynamic type bindings with v-model correctly utilize the dynamic model helper.
  • Bug Fixes

    • Improved detection of dynamic type bindings on input elements, ensuring proper handling when using shorthand syntax with v-model.

Copy link

github-actions bot commented Apr 8, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.3 kB 34.5 kB
vue.global.prod.js 159 kB (+6 B) 58.5 kB (+2 B) 52 kB (+25 B)

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.8 kB 23 kB 20.9 kB
defineCustomElement 59.5 kB 22.8 kB 20.8 kB
overall 68.6 kB 26.4 kB 24.1 kB

Copy link

pkg-pr-new bot commented Apr 8, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13170

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13170

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13170

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13170

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13170

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13170

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13170

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13170

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13170

vue

npm i https://pkg.pr.new/vue@13170

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13170

commit: 78a11fe

@edison1105 edison1105 changed the title fix(compiler-dom): handle v-model + v-bind shorthand edge case fix(compiler-dom): handle v-model + v-bind shorthand type edge case Apr 8, 2025
@edison1105 edison1105 added scope: compiler has workaround A workaround has been found to avoid the problem 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Apr 8, 2025
@@ -63,6 +63,13 @@ describe('compiler: transform v-model', () => {
expect(generate(root).code).toMatchSnapshot()
})

test('input with v-bind shorthand type should use dynamic model', () => {
const root = transformWithModel('<input :type v-model="model" />')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering whether it might be better to write this test with the :type after the v-model? Or both?

I understand that the test is following the order from the other tests, but in practice the order :type v-model="model" already works when using the full compiler (including the vBind transform), it only fails when the :type comes after the v-model.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the tests via 78a11fe

Copy link

coderabbitai bot commented May 26, 2025

"""

Walkthrough

The changes update the logic for detecting the type attribute in the v-model transform to better handle shorthand dynamic bindings (e.g., :type). An additional test case is added to verify that shorthand dynamic type bindings correctly trigger the use of the dynamic model helper.

Changes

File(s) Change Summary
packages/compiler-dom/src/transforms/vModel.ts Modified findProp call for type attribute to include flags for handling dynamic shorthand bindings.
packages/compiler-dom/tests/transforms/vModel.spec.ts Added a test case to cover shorthand dynamic :type with v-model and assert correct helper usage.

Sequence Diagram(s)

sequenceDiagram
    participant Template as Template Compiler
    participant vModelTransform as v-model Transform
    participant findProp as findProp Utility
    participant CodeGen as Code Generator

    Template->>vModelTransform: Parse <input :type v-model="...">
    vModelTransform->>findProp: findProp(node, 'type', false, true)
    findProp-->>vModelTransform: Return type prop info (shorthand dynamic)
    vModelTransform->>CodeGen: Use V_MODEL_DYNAMIC helper
Loading

Assessment against linked issues

Objective Addressed Explanation
Correctly handle shorthand :type binding with v-model to fix radio group behavior (#13169)
Ensure dynamic model helper is used when :type shorthand is present (#13169)

Suggested labels

ready to merge, scope: sfc

Poem

A rabbit hops with nimble might,
To fix the bug with radio type,
Shorthand binds now work just right,
v-model dances in the light!
With helpers called and tests anew,
Our code is crisp, our joy is true.
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 44d53ef and 78a11fe.

⛔ Files ignored due to path filters (1)
  • packages/compiler-dom/__tests__/transforms/__snapshots__/vModel.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • packages/compiler-dom/__tests__/transforms/vModel.spec.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/compiler-dom/tests/transforms/vModel.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test / e2e-test
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@edison1105 edison1105 requested a review from skirtles-code June 4, 2025 13:13
@skirtles-code
Copy link
Contributor

It seems like we have a lot of these edge cases around v-bind shorthand. e.g. #12298 and #12828. I'm wondering whether we need a rethink.

Would it be better to handle this at an earlier stage, rather than in the vBind transform?

I understand the desire to keep things modular by having v-bind logic all in the transform, but it seems like it's proving quite a leaky feature in practice, with bits of code needing tweaking all over to get it working in all the edge cases.

@edison1105
Copy link
Member Author

@skirtles-code
I've made a new PR #13438

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem scope: compiler
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Same-name shorthand (:type) breaks radio group behavior
2 participants